from datetime import timedelta
import os

os.umask(0o002)

### Set the time after which the admin session expires
# There are two sessions on pagure, login that holds for 31 days and
# the session defined here after which an user has to re-login.
# This session is used when accessing all administrative parts of pagure
# (ie: changing a project's or a user's settings)
ADMIN_SESSION_LIFETIME = timedelta(minutes=20)

### Secret key for the Flask application
SECRET_KEY='{{ distgit_pagure_secret_key }}'
SALT_EMAIL='{{ distgit_pagure_secret_salt_email }}'

{% if env == 'staging' %}
EMAIL_SEND = False
{% else %}
EMAIL_SEND = True
{% endif %}

# This is required so that login specifies https
PREFERRED_URL_SCHEME='https'

### url to the database server:
#DB_URL=mysql://user:pass@host/db_name
#DB_URL=postgres://user:pass@host/db_name
DB_URL = 'postgresql://{{ distgit_pagure_db_user }}:{{ distgit_pagure_db_pass }}@{{ distgit_pagure_db_host }}/{{ distgit_pagure_db_name }}'

### FAS groups of pagure admins
ADMIN_GROUP = ['cvsadmin', 'sysadmin-main']

### The email address to which the flask.log will send the errors (tracebacks)
EMAIL_ERROR = 'pingou@pingoured.fr'

### Default SMTP server to use for sending emails
SMTP_SERVER = 'bastion'

### Email used to sent emails
{% if env == 'staging' %}
FROM_EMAIL = 'pagure@pkgs.stg.fedoraproject.org'
DOMAIN_EMAIL_NOTIFICATIONS = 'src.stg.fedoraproject.org'
{% else %}
FROM_EMAIL = 'pagure@pkgs.fedoraproject.org'
DOMAIN_EMAIL_NOTIFICATIONS = 'src.fedoraproject.org'
{% endif %}

### The URL at which the project is available.
{% if env == 'staging' %}
APP_URL = 'https://src.stg.fedoraproject.org/'
{% else %}
APP_URL = 'https://src.fedoraproject.org/'
{% endif %}

### Datagrepper info for the user profile
{% if env == 'staging' %}
DATAGREPPER_URL = 'https://apps.stg.fedoraproject.org/datagrepper'
{% else %}
DATAGREPPER_URL = 'https://apps.fedoraproject.org/datagrepper'
{% endif %}
DATAGREPPER_CATEGORY = 'pagure'

### The URL to use to clone git repositories.
{% if env == 'staging' %}
GIT_URL_SSH = 'ssh://{username}@pkgs.stg.fedoraproject.org/'
GIT_URL_GIT = 'https://src.stg.fedoraproject.org/'
{% else %}
GIT_URL_SSH = 'ssh://pkgs.fedoraproject.org/'
GIT_URL_GIT = 'https://src.fedoraproject.org/'
{% endif %}

### The IP addresses allowed for the internal endpoints
{% if env == 'staging' %}
IP_ALLOWED_INTERNAL = ['127.0.0.1', 'localhost', '::1', '10.5.128.177']
{% else %}
IP_ALLOWED_INTERNAL = ['127.0.0.1', 'localhost', '::1', '10.5.126.51']
{% endif %}

# Redis configuration
{% if env == 'staging' %}
#EVENTSOURCE_SOURCE = 'https://src.stg.fedoraproject.org:8088'
{% else %}
#EVENTSOURCE_SOURCE = 'https://src.stg.fedoraproject.org:8088'
{% endif %}
REDIS_HOST = '0.0.0.0'
REDIS_PORT = 6379
REDIS_DB = 0

WEBHOOK = True

### Folder containing to the git repos
GIT_FOLDER = '/srv/git/repositories'

### Folder containing the docs repos
#DOCS_FOLDER = '/srv/git/repositories/docs'
DOCS_FOLDER = None

### Folder containing the pull-requests repos
REQUESTS_FOLDER = '/srv/git/repositories/requests'

### Folder containing the tickets repos
#TICKETS_FOLDER = '/srv/git/repositories/tickets'
TICKETS_FOLDER = None

### Folder containing the clones of the remotes git repo
REMOTE_GIT_FOLDER = '/srv/git/remotes'

### Folder where to run gl-compile-conf from
GITOLITE_HOME = '/srv/git/'

### Configuration file for gitolite
GITOLITE_CONFIG = '/srv/git/.gitolite/conf/gitolite.conf'

### File to include at the top of the gitolite configuration file
GITOLITE_PRE_CONFIG = '/var/tmp/gitolite-prefix.txt'

### Temp folder to be used to make the clones to work around bug in libgit2:
## refs: https://github.com/libgit2/libgit2/issues/2965
## and   https://github.com/libgit2/libgit2/issues/2797
TMP_FOLDER = '/srv/tmp'

# Optional configuration

### Number of items displayed per page
# Used when listing items
ITEM_PER_PAGE = 48

### Maximum size of the uploaded content
# Used to limit the size of file attached to a ticket for example
MAX_CONTENT_LENGTH = 2 * 1024 * 1024  # 2 megabytes

### Lenght for short commits ids or file hex
SHORT_LENGTH = 6

# Authentication related configuration option

### Switch the authentication method
# Specify which authentication method to use, defaults to `fas` can be or
# `local`
# Default: ``fas``.
PAGURE_AUTH = 'fas'

# When this is set to True, the session cookie will only be returned to the
# server via ssl (https). If you connect to the server via plain http, the
# cookie will not be sent. This prevents sniffing of the cookie contents.
# This may be set to False when testing your application but should always
# be set to True in production.
# Default: ``True``.
SESSION_COOKIE_SECURE = True

# The name of the cookie used to store the session id.
# Default: ``.pagure``.
SESSION_COOKIE_NAME = 'disgit_pagure'

# Boolean specifying wether to check the user's IP address when retrieving
# its session. This make things more secure (thus is on by default) but
# under certain setup it might not work (for example is there are proxies
# in front of the application).
CHECK_SESSION_IP = True

# Used by SESSION_COOKIE_PATH
APPLICATION_ROOT = '/'

# Set the SSH certs/keys
{% if env == 'staging' %}
SSH_KEYS = {
    'RSA': {
        'fingerprint': '2048 ce:e8:a7:2b:7a:6a:9c:6f:f0:e7:ab:bb:a0:c4:f3:f2   (RSA)',
        'pubkey': 'pkgs.stg.fedoraproject.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7kE4Zst3uYFPdoJN341v+annUShkcu+ODT93JX95OfOwbqQP3ZeCG3Nl1+mHOcRg8mRqxmf8FadzjSVoGKf8rWdAQA4vawS8b98XyHp7oCIS6Ydv+wVtFy1ecGHn9yEvuiVLU6G2nn9LJ5rVbNa/dtLUZp9VA+zxQo/wmVGON/XdH9i3pGzCzQb+aRr2xW0uEGJAnLQd04URi7skpsX9EhZcc/aPgrOH5A/jacECN1c/6bS/J+ReNoohqaoj0JZB+4sPX71YoaMOgEZz7z9o7qmKQhSC6iH08nLY53kcy+geSMoFxbokFupnrvof5Ck5MHIYucPnuj7EUrB2srAyD',
        'SHA256': 'SHA256:+WoPGFGoQqGMYdT4wc4T8XFr2ounR4dHNfdmNEI9Dfo',
    }
}
{% else %}
SSH_KEYS = {
    'RSA': {
        'fingerprint': '2048 fe:2e:6a:86:f3:41:e7:03:95:ea:9c:7f:75:9c:ce:9d   (RSA)',
        'pubkey': 'pkgs.fedoraproject.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAnhQyqu6oY5g01SOEbtrgrlCk3/eoLVZl2oh6c+Xq2oJg5ppPCtvmdWgU9rEltS+jgAYTH3LG4lGd02boMk8mmV5QvzGGRA9HmN991Phm7y4EN5r84A0gibf2O5QzhU2IMBQuOkEMwqZC+wc7pGGFJeXQjzBAVidjacxXtVJyfFOhAIYoHerIYq3VbJrTzEGkHmcJ8o3ZnP8Mt35aBESNsHdIaCOpvZzK1NVHdUHwRGcXIjG6t06mNVG4DVbdpB6xmMbAD5bemPoPVG0oYVs9wmhSHC0LmOZbvv8CDO2Z0DJ8q25FwVlTjo1Eq2A8VJc4LnHTDHZbtDZiKGTo/UMvvQ==',
        'SHA256': 'SHA256:Q12OTyTeOHWlS54dTzy2BNu7wB8UKNf18+7WHIDsORc',
    }
}
{% endif %}


# Configuration item that are specific for this odd pagure instance

PROJECT_TICKETS = False
ENABLE_NEW_PROJECTS = True
ENABLE_UI_NEW_PROJECTS = False
ENABLE_DEL_PROJECTS = False
ENABLE_DEL_FORKS = True
ENABLE_TICKETS = False
ENABLE_GROUP_MNGT = False
DEPLOY_KEY = False
LOCAL_SSH_KEY = False
ALLOW_DELETE_BRANCH = False
ALLOWED_PREFIX = ['rpms', 'modules', 'container']
EXCLUDE_GROUP_INDEX = ['packager']

DISABLED_PLUGINS = ['IRC', 'Pagure tickets', 'Read the Doc']

ACLS = {
    'create_project': 'Create a new project',
    'fork_project': 'Fork a project',
    'pull_request_close': 'Close a pull-request of this project',
    'pull_request_comment': 'Comment on a pull-request of this project',
    'pull_request_flag': 'Flag a pull-request of this project',
    'pull_request_merge': 'Merge a pull-request of this project',
    'modify_project': 'Modify an existing project',
    'generate_acls_project': 'Generate the Gitolite ACLs on a project',
}

EXTERNAL_COMMITTER = {
    'fedora-altarch': {},
    'provenpackager': {
        'exclude': ['rpms/xulrunner', 'rpms/thunderbird', 'rpms/firefox']
    }
}
REQUIRED_GROUPS = {
    'container/*': ['packager'],
    'modules/*': ['packager'],
    'rpms/*': ['packager'],
}

{% if env == 'staging' %}
PDC_URL = 'https://pdc.stg.fedoraproject.org/rest_api/v1/'
RESULTSDB_URL = 'https://taskotron.stg.fedoraproject.org/resultsdb_api/'
FAS_URL = 'https://admin.stg.fedoraproject.org/accounts'
{% else %}
PDC_URL = 'https://pdc.fedoraproject.org/rest_api/v1/'
RESULTSDB_URL = 'https://taskotron.fedoraproject.org/resultsdb_api/'
FAS_URL = 'https://admin.fedoraproject.org/accounts'
{% endif %}

GITOLITE_BACKEND = 'distgit'
GITOLITE_CELERY_QUEUE = 'gitolite_queue'

CASE_SENSITIVE = True

THEME_TEMPLATE_FOLDER = '/usr/share/pagure_dist_git/template/'

USER_ACLS = [
    'fork_project',
    'pull_request_close',
    'pull_request_comment',
    'pull_request_flag',
    'pull_request_merge',
    'modify_project',
]

CROSS_PROJECT_ACLS = [
    'fork_project',
    'modify_project'
]

ADMIN_API_ACLS = [
    'pull_request_flag',
    'pull_request_comment',
    'pull_request_merge',
    'create_project',
    'modify_project',
    'generate_acls_project',
]

BLACKLISTED_GROUPS = ['forks', 'group']

PROJECT_NAME_REGEX = '^[a-zA-z0-9_][a-zA-Z0-9-_\.+]*$'

